<template>
  <div id="app">
    <div>
      <h3>
        猫の庭院
        <div class="right-nav">
          <div v-if="!userInfo.user_id">
            <span class="right" @click="goToPath('/register')">注册</span>
            <span class="right" @click="goToPath('/login')">登录</span>
          </div>
          <div v-else>
            <span
              class="right"
              @click="showLogout(true)"
              @mouseenter="showLogout(true)"
              @mouseleave="showLogout(false)"
            >{{userInfo.user_nickname?userInfo.user_nickname:userInfo.user_email}}</span>
            <span class="right" @click="goToPath('/orders')">我的订单</span>
            <div
              class="right-box"
              @mouseenter="showLogout(true)"
              @mouseleave="showLogout(false)"
              v-if="showRightBoxStatus"
            >
              <span @click="goToPath('/login')">退出登录</span>
            </div>
          </div>
        </div>
      </h3>
    </div>
    <router-view />
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      userInfo: {
        user_id: 0
      },
      showRightBoxStatus: false
    };
  },
  mounted() {
    const userInfo = JSON.parse(window.localStorage.getItem("userInfo"));
    if (userInfo) {
      this.userInfo = userInfo;
    }
  },
  methods: {
    goToPath: function(path) {
      this.$router.push(path);
    },
    showLogout(status) {
      this.showRightBoxStatus = status;
    }
  }
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

h3 {
  text-align: center;
}

.right-nav {
  position: absolute;
  top: 25px;
  right: 30px;
  font-size: 12px;
  font-weight: 300;
}

.right-box {
  position: fixed;
  right: 0;
  top: 40px;
  overflow: hidden;
  z-index: 1000;
}
.right {
  float: right;
  font-size: 12px;
  margin-right: 15px;
  cursor: pointer;
}
.right-box span {
  z-index: 1000;
  background: #fff;
  width: 80px;
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 12px;
  display: block;
  cursor: pointer;
}
</style>
